<template>
  <a-config-provider :locale="locale">
    <div id="app">
      <router-view/>
    </div>
  </a-config-provider>
</template>
<script>
  import zhCN from 'ant-design-vue/lib/locale-provider/zh_CN'
  import enUS from 'ant-design-vue/lib/locale-provider/en_US'
  import enquireScreen from '@/utils/device'
  import { get_langKey } from '@/common/storage.js'

  function setLanguage() {
    let userLanguage = navigator.language || navigator.userLanguage; // 对于非英语环境，可能需要navigator.userLanguage兼容性处理
    if (userLanguage === 'zh' || userLanguage === 'zh-CN') {
        // 加载中文内容或设置中文界面
        console.log('设置中文');
        return 'zh_cn'
    } else if (userLanguage === 'en' || userLanguage === 'en-US') {
        // 加载英文内容或设置英文界面
        console.log('设置英文');
        return 'en_us'
    } else {
        // 默认语言处理
        console.log('使用默认语言');
        return 'zh_cn'
    }
  }
  export default {
    data () {
      return {
        // locale: zhCN,
        // locale: enUS,
        locale: '',
      }
    },
    created () {
      let that = this
      let langKey = get_langKey() || setLanguage()
      if (langKey === 'zh_cn') {
        that.locale = zhCN 
      }else if (langKey === 'en_us') {
        that.locale = enUS 
      }else{
        that.locale = zhCN
      }
      enquireScreen(deviceType => {
        // tablet
        if (deviceType === 0) {
          that.$store.commit('TOGGLE_DEVICE', 'mobile')
          that.$store.dispatch('setSidebar', false)
        }
        // mobile
        else if (deviceType === 1) {
          that.$store.commit('TOGGLE_DEVICE', 'mobile')
          that.$store.dispatch('setSidebar', false)
        }
        else {
          that.$store.commit('TOGGLE_DEVICE', 'desktop')
          that.$store.dispatch('setSidebar', true)
        }

      })
    }
  }
</script>
<style lang="less">
  @import url("common/style/base.global.css");

  #app {
    height: 100%;
  }

  /* 自定义NProgress样式 */
  /* #nprogress .bar {
    background: #148958 !important;
  } */
</style>
